import {axios} from "../utils/request";
import global from "../store/global";

const api = global.serverAddress + "/relation";

// 某一个图下的所有relation
export function getGraphRelationsByIdAPI(graphId) {
    return axios({
        url: `${api}/get_graph_relation/${graphId}`,
        method: "GET"
    });
}

// 获得id为node相关的所有关系
export function getGraphNodesByIdAPI(nodeId) {
    return axios({
        url: `${api}/get_node_relation/${nodeId}`,
        method: "GET"
    });
}

// 根据id获得relation
export function getRelationByIdAPI(relationId) {
    return axios({
        url: `${api}/get/${relationId}`,
        method: "GET"
    });
}


// 添加关系
export function addRelationAPI(params) {
    return axios({
        url: `${api}/add/${params.graphId}/${params.sourceId}/${params.targetId}/${params.ship}/${params.type}`,
        method: "POST"
    });
}


// 根据id删除关系
export function deleteRelationByIdAPI(relationId) {
    return axios({
        url: `${api}/delete/${relationId}`,
        method: "POST"
    });
}

// 根据id更新关系
export function updateRelationAPI(relation) {
    return axios({
        url: `${api}/update`,
        method: "POST",
        data: relation
    });
}